home *** CD-ROM | disk | FTP | other *** search
- Path: keats.ugrad.cs.ubc.ca!not-for-mail
- From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
- Newsgroups: comp.lang.c
- Subject: Re: Algorithm - intersection of lines!
- Date: 19 Jan 1996 15:23:03 -0800
- Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
- Message-ID: <4dp94nINN822@keats.ugrad.cs.ubc.ca>
- References: <4bebi9$eik@news.infi.net> <e3f_9601030228@tor250.org> <4crl7v$bju@news.microsoft.com>
- NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
-
- In article <4crl7v$bju@news.microsoft.com>,
- Dann Corbit <a-cnadc@microsoft.com> wrote:
- >In article <e3f_9601030228@tor250.org>, Philip.Davis@fknights.gryn.org says...
- >>
- >> nn> Finding the intersection of lines is not trivial.
- >>
- >>But if you have the equations of the lines, can't you simply set the
- >>equations equal, and solve for x and y (which gives the point of
- >>intersection...) just some grade 11 math which occurred to me.
- >
- >Parralel? Infinite or zero slope? Not in the same plane?
-
- If they are not in the same plane, you are dealing with 3-D intersections, for
- which you can use a different approach. I don't have access to the original
- post, so I don't know which was being called for.
-
- If you define a (2D) line as an implicit equation in the form Ax + By + D = 0,
- you never run into problem stemming from zero or infinite slope. One would
- have to be quite naive to try to represent the line as y = mx + b!
-
- A line with an infinite slope just has a left or right pointing normal
- vector; that is, <A, B> = <N, 0>, where N is some non-zero number.
- The equation looks like Ax + 0y + D = 0, and its treatment presents no special
- problem. A line with zero slope is just of the form 0x + By + D = 0.
-
- >Numerically parallel? Coincident?
-
- This can be checked by looking at the normal vectors, <A1, B1> and <A2, B2>.
- If these are parallel, the lines are parallel. You simply check whether
- the dot product of <A1, B1> and <-B2, A2> is zero. No need to worry about
- infinite or zero slopes. No division required.
-
- To check if the lines are coincident, first check whether they are parallel. If
- so, check if the both share a point. Substitute a point that you know is on
- either line into the implicit equation of the other, and check that it it is
- within some tolerance of zero. For this, it may be useful to have an arbitrary
- point on the line as part of your data structure.
-
- >Not trivial. An intersection routine can be fairly compact, but
- >a good one will definitely require some careful thinking.
-
- True, but it is a fairly easy problem to solve. You don't need any heavy
- numerical analysis, just bit of linear algebra and common sense.
-
- To do the 3D version of the problem, it's probably best to think of one of
- the lines as a parametrized ray, and the other as a cylinder of some finite
- thickness.
- --
-
-